
package com.xiaoyi.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avin.yi.R;

import java.util.List;


public class XyPicTypeListAdapter extends RecyclerView.Adapter {

    private List<String> mDataList;
    private Context context;
    private LayoutInflater mInflater;


    public XyPicTypeListAdapter(Context context) {

        this.context = context;
        mInflater = LayoutInflater.from(context);
    }


    public void notifyDataSetChanged(List<String> mDataList ) {

        this.mDataList = mDataList;
        super.notifyDataSetChanged();
    }


    public String getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public int getItemCount() {
        return mDataList == null ? 0 : mDataList.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(R.layout.item_onetxt, parent, false));
    }


    @Override
    public int getItemViewType(int position) {
        return 0;
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (holder instanceof ViewHolder) {
            ((ViewHolder) holder).setData(mDataList.get(position), context);
        }

    }


    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.setData(mDataList.get(position), context);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView title;

        public ViewHolder(View itemView) {
            super(itemView);
            title = itemView.findViewById(R.id.title);
        }

        public void setData(String data, Context context) {
            title.setText(data);
        }
    }

}
